package com.j.lemon.learn.flink.datastream;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger;

/**
 * 窗口函数
 * @author lijunjun
 */
public class WindowOperator {
    public static void main(String[] args) throws Exception {
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//        DataStream<Tuple2<String,Integer>> dataStream = env.socketTextStream("127.0.0.1",8888)
//                .map(new MapFunction<String, Tuple2<String,Integer>>() {
//                    @Override
//                    public Tuple2<String, Integer> map(String s) throws Exception {
//                        return new Tuple2<>(s,1);
//                    }
//                })
//        .keyBy(new KeySelector<Tuple2<String, Integer>, String>() {
//            @Override
//            public String getKey(Tuple2<String, Integer> stringIntegerTuple2) throws Exception {
//                return stringIntegerTuple2.f0;
//            }
//        }).window(TumblingProcessingTimeWindows.of(Time.seconds(2))).allowedLateness(Time.seconds(60L)).sum(1);
//        dataStream.print();
//
//        env.execute();


    }
}
